# Maintainer: Santiago Torres-Arias <santiago at archlinux dot org>
# Maintainer: Daniel Milde <daniel at milde dot cz>

pkgname=container-diff
pkgver=0.17.0
pkgrel=3
pkgdesc="Diff your Docker containers"
arch=(loong64 x86_64)
url="https://github.com/GoogleContainerTools/container-diff"
license=('Apache')
depends=('glibc')
makedepends=("go" "git")
checkdepends=("docker")
source=("git+https://github.com/GoogleContainerTools/container-diff#tag=v${pkgver}")
sha512sums=('SKIP')

prepare() {
  mkdir -vp "${srcdir}/src/github.com/GoogleContainerTools/"
  mv "${srcdir}/${pkgname}" "${srcdir}/src/github.com/GoogleContainerTools/${pkgname}"
}

build() {
  cd "${srcdir}/src/github.com/GoogleContainerTools/${pkgname}"
  export GOPATH="${srcdir}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"
  make clean && make
}

check() {
  #FIXME: This may ETIMEOUT if your computer is not fast enough...
  #FIXME: we also need to instantiate our custom docker daemon
  # (if you want to build on a chroot), which is rather tricky...
  cd "${srcdir}/src/github.com/GoogleContainerTools/${pkgname}"
  export GOPATH="${srcdir}"
  make test integration -j | true
}

package() {
  install -D -m0755 "src/github.com/GoogleContainerTools/${pkgname}/out/${pkgname}" "${pkgdir}/usr/bin/${pkgname}"
  install -Dm0644 "src/github.com/GoogleContainerTools/${pkgname}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}"
}
